<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('strator_login_logs', function (Blueprint $table) {
            $table->id();

            $table->unsignedInteger('strator_id')->nullable()->index()->comment('管理员id');
            $table->ipAddress('ip')->nullable()->index()->comment('登录ip');
            $table->string('referer')->nullable()->comment('请求来源');
            $table->string('user_agent')->nullable()->comment('浏览器agent信息');
            $table->char('client_type',32)->nullable()->comment('登录客户端类型');
            $table->tinyInteger('login_result')->default(1)->index()->comment('登录结果:默认1成功，0失败');
            $table->string('failed_reason')->nullable()->comment('失败原因');
            $table->char('failed_account',64)->nullable()->index()->comment('失败账号（含手机号，邮箱，用户名等）');
            $table->char('failed_password',64)->nullable()->comment('失败用的密码');

            $table->timestamps();
            $table->softDeletes();
        });

        \DB::statement("ALTER TABLE `strator_login_logs` comment '管理员登录日志表'");
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('strator_login_logs');
    }
};
